<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro-gray/easyui.css"/>
<link rel="stylesheet" href="static/easyui/themes/icon.css"/>
<title>处方开药</title>
</head>
<body>
<script type="text/javascript">
//时间转换
function comformatDate(date) {
	var day = new Date(date); 
	var Year = 0; 
	var Month = 0; 
	var Day = 0; 
	var CurrentDate = ""; 
	//初始化时间 
	Year= day.getFullYear();//
	Month= day.getMonth()+1; 
	Day = day.getDate(); 
	Hour = day.getHours(); 
	 Minute = day.getMinutes(); 
	 Second = day.getSeconds(); 
	CurrentDate += Year + "-"; 
	if (Month >= 10 ) { 
		CurrentDate += Month + "-"; 
	}else { 
		CurrentDate += "0" + Month + "-"; 
	} 
	if (Day >= 10 ) { 
		CurrentDate += Day ; 
	}else { 
		CurrentDate += "0" + Day ; 
	} 
	if(Hour>=10){
		CurrentDate +=" "+Hour;
	}else{
		CurrentDate +=" "+"0"+Hour;
	}
	if(Minute>=10){
		CurrentDate +=":"+Minute;
	}else{
		CurrentDate +=":"+"0"+Minute;
	}
	if(Second>=10){
		CurrentDate +=":"+Second;
	}else{
		CurrentDate +=":"+"0"+Second;
	}
	return CurrentDate; 
};

	function zhichuxq(c){
		$("#zcxq").window("open");
		//访问数据源、初始化表格
		$('#zcypxq').datagrid({
			url:'zcypjl',
			singleSelect:true,
			queryParams:{
				cfid:c
			},
			columns:[[
						{field:'cfid',title:'处方编号',width:100},
						{field:'ypid',title:'药品id',width:100},
						{field:'ypname',title:'药品名称',width:100},
						{field:'ypdj',title:'药品单价',width:100,align:'right'},
						{field:'yppc',title:'药品批次',width:100,align:'right'},
						{field:'ypsl',title:'药品数量',width:100,align:'right'},
						{field:'bz',title:'备注',width:100,align:'right'}
					]]
					
			});
	}
	
	function bmzhichu(a){
		$("#bmzc").window("open");
		//访问数据源、初始化表格
		$('#bmzcxq').datagrid({
			url:'bmjlxq',
			singleSelect:true,
			queryParams:{
				sqid:a
			},
			columns:[[
						{field:'sqid',title:'申请编号',width:100},
						{field:'ypid',title:'药品id',width:100},
						{field:'ypname',title:'药品名称',width:100},
						{field:'yppc',title:'药品批次',width:100,align:'right'},
						{field:'ypsl',title:'药品数量',width:100,align:'right'},
					]]
					
			});
	}
	var n="${user.userName }";
	var date = new Date(+new Date()+8*3600*1000).toISOString().replace(/T/g,' ').replace(/\.[\d]{3}Z/,'');
	function yzytuihuo(a,b,c){
		$("#thsl").window("open");
		zhichutj(a,b,c);
	}
	function zhichutj(ypid,yppc,ypdj){
		var ypnb=$("#ypnumber").val();
		var row = $('#zcypxq').datagrid("getSelected");
		alert(row.cfid);
		alert(row.ypid);
		alert(ypnb);
		$("<form method='post'>").appendTo("body").form({
			url:'yptuihuo',
			onSubmit:function (param){
				//时间
				param["order.returnDateYf"] = date;
				//经办人
				param["order.returnJbr"] = n;
				//卡号
				param["order.prescriptionPx.prescriptionId"] = row.cfid;
				//退货原因
				param["order.returnDetaiYf"] = "多余";

					//药品编号
					param["details.drugsYk.drugId"] = row.ypid;
					//药品批次
					param["details.yppc"] = row.yppc;
					//价格
					param["details.redetaiMoneyYf"] = row.ypdj;
					//采购数量
					param["details.redetaiNumberYf"] = ypnb;
				
			},
			success:function(d){
				alert(d);
			}
		}).submit();
	}


	
	$(function(){
		//访问数据源、初始化表格
		$('#chufangzc').datagrid({
			url:'zcjl',
			columns:[[
						{field:'cfid',title:'处方编号',width:100},
						{field:'cfcard',title:'医疗卡号',width:100},
						{field:'cfys',title:'开药医生',width:100,align:'right'},
						{field:'cftime',title:'支出时间',width:100,align:'right',formatter:comformatDate},
						{field:'cfr',title:'病人姓名',width:100,align:'right'},
						{field:'cfmn',title:'总金额',width:100,align:'right'},
						{field:'cz',title:'操作*',width:200,
							formatter:function(value,row,index){
								return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='zhichuxq("+row.cfid+")' value='详情'/>";
							}	
						}
					]]
					
			});
		
		//名字查询
		$('#ylkcx').searchbox({
			searcher:function(value){
			    alert(value);
			    	   $('#chufangzc').datagrid({
		    				url:'ylkcx',
		    				queryParams:{
		    					nameq:value
		    				},
		    				columns:[[
		    					{field:'cfid',title:'处方编号',width:100},
								{field:'cfcard',title:'医疗卡号',width:100},
								{field:'cfys',title:'开药医生',width:100,align:'right'},
								{field:'cftime',title:'支出时间',width:100,align:'right',formatter:comformatDate},
								{field:'cfr',title:'病人姓名',width:100,align:'right'},
								{field:'cfmn',title:'总金额',width:100,align:'right'},
								{field:'cz',title:'操作*',width:200,
									formatter:function(value,row,index){
										return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='zhichuxq("+row.cfid+")' value='详情'/>";
									}	
								}
		    						]]
							});
			    }
			    
			  
		});
		
		//访问数据源、初始化表格
		$('#bmxq').datagrid({
			url:'bmzcjl',
			columns:[[
						{field:'sqid',title:'申请编号',width:100},
						{field:'bmtime',title:'申请时间',width:100,formatter:comformatDate},
						{field:'jbr',title:'经办人',width:100,align:'right'},
						{field:'cz',title:'操作*',width:200,
							formatter:function(value,row,index){
								return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='bmzhichu("+row.sqid+")' value='详情'/>";
							}	
						}
					]]
					
			});
		
		//名字查询
		$('#bmidcx').searchbox({
			searcher:function(value){
			    alert(value);
			    	   $('#bmxq').datagrid({
		    				url:'bmidcx',
		    				queryParams:{
		    					nameq:value
		    				},
		    				columns:[[
		    					{field:'sqid',title:'申请编号',width:100},
								{field:'bmtime',title:'申请时间',width:100,formatter:comformatDate},
								{field:'jbr',title:'经办人',width:100,align:'right'},
								{field:'cz',title:'操作*',width:200,
									formatter:function(value,row,index){
										return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='bmzhichu("+row.sqid+")' value='详情'/>";
									}	
								}
		    						]]
							});
			    }
			    
			  
		});
		
	})
</script> 

<div  class="easyui-panel" data-options="fit:true">
	<div class="easyui-tabs">
		<div title="处方支出">
			<p>
		请输入医疗卡号:<input id="ylkcx" class="easyui-searchbox"/>
		</p>
					<table id="chufangzc" class="easyui-datagrid" data-options="fitColumns:true,pagination:true"  style="height:400px">
					
					</table>
			</div>
			<div title="部门支出">
			<p>
			请输入部门名称:<input id="bmidcx" class="easyui-searchbox"/>
			</p>
					<table id="bmxq" class="easyui-datagrid" data-options="fitColumns:true,pagination:true"  style="height:400px">
						
				</table>
			</div>
		</div>
		<div id="zcxq" title="处方支出详情" class="easyui-window" data-options="closed:true">
				<table id="zcypxq"  class="easyui-datagrid" data-options="fitColumns:true,pagination:true"  style="height:400px" width="500px">
				
				</table>
		</div>
		
		<div id="bmzc" title="部门支出详情" class="easyui-window" data-options="closed:true">
				<table id="bmzcxq"  class="easyui-datagrid" data-options="fitColumns:true,pagination:true"  style="height:400px" width="500px">
				
				</table>
		</div>
		</div>
</body>
</html>